import javax.xml.soap.Node;

public class LeetCode_203_2 {
    public ListNode removeElements(ListNode head, int val) {
        ListNode dummyNode = new ListNode(-1);
        dummyNode.next = head;
        ListNode pre = dummyNode;
        while(pre.next != null){
            if(pre.next.val == val){
                ListNode retNode = pre.next;
                pre.next = retNode.next;
                retNode.next = null;
            }else{
                pre = pre.next;
            }
        }
        return dummyNode.next;
    }

    public static void main(String[] args) {
        int[] nums = {1,2,6,3,4,5,6};
        ListNode head = new ListNode(nums);
        System.out.println(head);
        new LeetCode_203_2().removeElements(head,6);
        System.out.println(head);
    }
}
